home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
SSDrawStyle.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
15KB
|
375 lines
class SSDrawStyle extends SSDrawing
{
var offsetX = 0;
var offsetY = 0;
var mainFillLayer = 20;
var store = false;
var types = {fillTexture:"string",fillColor:"hex",viewSlope:"vector",lightDirection:"vector"};
var defaultType = "number";
var caseSensitive = true;
var capEnd = true;
var className = "SSDrawStyle";
var editor_drawStyle = true;
static var editor_ignore = true;
function SSDrawStyle()
{
super();
}
function setup()
{
this.viewSlope = SSGlobal.DRAW_VIEW_DIRECTION;
this.surfaceEdge = new SSMaterial();
this.wallEdge = new SSMaterial();
this.emptyEdge = new SSMaterial();
}
function define()
{
}
function applyNodeToObject(obj, node)
{
var _loc3_ = node.attributes;
var _loc1_ = undefined;
var _loc4_ = undefined;
for(var _loc5_ in _loc3_)
{
if((_loc4_ = obj.types[_loc5_]) == null)
{
_loc4_ = obj.defaultType;
}
switch(_loc4_)
{
case "hex":
_loc1_ = GDK.Tools.hexToNumber(_loc3_[_loc5_]);
if(!isNaN(_loc1_))
{
obj[_loc5_] = _loc1_;
}
break;
case "number":
_loc1_ = Number(_loc3_[_loc5_]);
if(!isNaN(_loc1_))
{
obj[_loc5_] = _loc1_;
}
break;
case "string":
_loc1_ = _loc3_[_loc5_];
if(_loc1_.length > 0)
{
obj[_loc5_] = _loc1_;
}
break;
case "vector":
_loc1_ = _loc3_[_loc5_].split(",");
_loc1_ = new Vector(Number(_loc1_[0]),Number(_loc1_[1]),Number(_loc1_[2]));
if(_loc1_.length != NaN)
{
obj[_loc5_] = _loc1_;
}
}
}
}
function defineFromXML()
{
if(this.styleXML == null)
{
return undefined;
}
this.applyNodeToObject(this,this.styleXML);
var _loc4_ = undefined;
var _loc2_ = undefined;
var _loc5_ = undefined;
var _loc3_ = _loc5_ = this.styleXML.childNodes.length;
while((_loc3_ = _loc3_ - 1) > -1)
{
if(_loc4_ = this[_loc2_ = _loc5_[_loc3_].nodeName + "Edge"])
{
this.applyNodeToObject(_loc4_,_loc2_);
}
}
delete this.styleXML;
}
function prepare()
{
this.viewSlope.normalize();
this.lightDirection.normalize();
this.surfaceEdge.prepare();
this.wallEdge.prepare();
this.emptyEdge.prepare();
}
function process()
{
this.capEnd = this.viewSlope.x >= 0 ? 1 : (this.viewSlope != 0 ? -1 : 0);
this.viewAngle = Math.atan2(- this.viewSlope.x,this.viewSlope.y) * 57.2957795;
this.mainFill(this.points);
var _loc2_ = this.groups.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this.groupFill(this.groups[_loc2_],this.groups[_loc2_].mask);
}
}
function mainFill(points)
{
this.setLayer(this.mainFillLayer);
if(this.fillTexture != null)
{
this.bitmapShape(this.fillTexture,points);
}
else if(this.fillColor != null)
{
this.setLayer(this.mainFillLayer);
this.solidShape(this.fillColor,points);
}
this.transform(this.offsetX,this.offsetY);
}
function pickStyle(mask)
{
if(mask & 1)
{
if(mask & 2)
{
return this.surfaceEdge;
}
return this.wallEdge;
}
return this.emptyEdge;
}
function createSegment(point, normal, edge, material, scale)
{
if(scale == null)
{
scale = 1;
}
var _loc7_ = this.viewSlope.x;
var _loc6_ = this.viewSlope.y;
var _loc3_ = point;
var _loc8_ = material.rearDepth <= 0 ? _loc3_ : new Vector(_loc3_.x - material.rearDepth * _loc7_,_loc3_.y - material.rearDepth * _loc6_,0);
var _loc9_ = material.frontDepth <= 0 ? _loc3_ : new Vector(_loc3_.x + material.frontDepth * _loc7_,_loc3_.y + material.frontDepth * _loc6_,0);
var _loc11_ = normal.dot(edge.normal);
if(material.thickness > 0)
{
var _loc13_ = material.thickness;
var _loc5_ = _loc13_ / _loc11_;
var _loc10_ = new Vector(_loc9_.x - normal.x * _loc5_ + material.sideExtrude * _loc7_,_loc9_.y - normal.y * _loc5_ + material.sideExtrude * _loc6_,0);
var _loc15_ = new Vector(_loc8_.x - normal.x * _loc5_ - material.sideExtrude * _loc7_,_loc8_.y - normal.y * _loc5_ - material.sideExtrude * _loc6_,0);
var _loc16_ = new Vector(_loc3_.x - normal.x * _loc5_,_loc3_.y - normal.y * _loc5_,0);
}
else
{
_loc10_ = _loc9_;
_loc15_ = _loc8_;
_loc16_;
}
var _loc14_ = !material.bottomDepth ? _loc10_ : new Vector(_loc10_.x - material.bottomDepth * _loc7_,_loc10_.y - material.bottomDepth * _loc6_,0);
var _loc12_ = [_loc8_,_loc3_,_loc9_,_loc10_,_loc14_,_loc16_,_loc15_];
(_loc12_.normal = new Vector(normal.x * _loc11_,normal.y * _loc11_,0)).normalize();
return _loc12_;
}
function groupFill(edges, mask)
{
var _loc3_ = edges[0].attributes;
if(_loc3_ == null)
{
return undefined;
}
var _loc17_ = new SSDrawing();
var _loc34_ = new SSDrawing();
var _loc35_ = new SSDrawing();
var _loc38_ = new SSDrawing();
var _loc40_ = edges[0].previous == edges[edges.length];
var _loc18_ = edges.length;
var _loc24_ = [];
var _loc2_ = undefined;
var _loc4_ = undefined;
var _loc7_ = _loc3_.ambientColor;
var _loc6_ = _loc3_.diffuseColor;
var _loc8_ = _loc3_.specularColor;
if(_loc40_)
{
_loc24_[_loc18_] = _loc24_[0] = this.createSegment(edges[0].a,edges[0].a.normal,edges[0],_loc3_);
}
else
{
switch(_loc3_.endAlign)
{
case 0:
default:
_loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].normal,edges[0],_loc3_);
_loc2_ = _loc0_;
_loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].normal,edges[_loc18_ - 1],_loc3_);
_loc4_ = _loc0_;
break;
case 1:
_loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].a.normal,edges[0],_loc3_);
_loc2_ = _loc0_;
_loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].b.normal,edges[_loc18_ - 1],_loc3_);
_loc4_ = _loc0_;
break;
case 2:
_loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].previous.direction,edges[0],_loc3_);
_loc2_ = _loc0_;
_loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].next.direction,edges[_loc18_ - 1],_loc3_);
_loc4_ = _loc0_;
}
if(_loc3_.capSurface && _loc3_.thickness > 0)
{
var _loc16_ = _loc2_.normal.cross(Vector.VECNZ);
if(this.viewSlope.dot(_loc16_) < 0)
{
var _loc11_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
_loc17_.solidShape(_loc11_,[_loc2_[1],_loc2_[2],_loc2_[3],_loc2_[5]]);
_loc34_.solidShape(_loc11_,[_loc2_[0],_loc2_[1],_loc2_[5],_loc2_[6]]);
}
_loc16_ = _loc4_.normal.cross(Vector.VECNZ);
if(this.viewSlope.dot(_loc16_) < 0)
{
_loc11_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
_loc17_.solidShape(_loc11_,[_loc4_[1],_loc4_[2],_loc4_[3],_loc4_[5]]);
_loc34_.solidShape(_loc11_,[_loc4_[0],_loc4_[1],_loc4_[5],_loc4_[6]]);
}
}
}
while(_loc18_ = _loc18_ - 1)
{
_loc24_[_loc18_] = this.createSegment(edges[_loc18_].a,edges[_loc18_].a.normal,edges[_loc18_],_loc3_);
}
var _loc36_ = !SSMaterial.TEXTURES_ENABLED ? null : _loc3_.surfaceTexture;
var _loc43_ = _loc3_.surfaceTextureMode;
var _loc19_ = _loc3_.sideExtrude;
var _loc20_ = _loc3_.smoothing;
var _loc42_ = 1 - _loc20_;
var _loc41_ = this.viewSlope.x * 180;
var _loc28_ = _loc3_.ratios;
var _loc25_ = _loc3_.alphas;
var _loc39_ = _loc3_.frontDepth + _loc3_.rearDepth;
var _loc37_ = undefined;
_loc18_ = edges.length;
_loc4_ = _loc24_[_loc18_];
var _loc5_ = undefined;
var _loc21_ = undefined;
var _loc26_ = edges[_loc18_ - 1].b;
var _loc13_ = undefined;
var _loc22_ = undefined;
var _loc27_ = _loc4_.normal;
var _loc32_ = undefined;
var _loc10_ = undefined;
var _loc14_ = undefined;
if(!_loc19_)
{
_loc14_ = this.calculateLighting(Vector.VECPZ,_loc7_,_loc6_,_loc8_).valueOf();
}
while((_loc18_ = _loc18_ - 1) > -1)
{
_loc21_ = edges[_loc18_].a;
_loc2_ = _loc24_[_loc18_];
_loc13_ = _loc5_ = edges[_loc18_].normal;
_loc22_ = _loc2_.normal;
if((_loc37_ = this.viewSlope.dot(_loc5_.normal) < 0) && _loc39_ > 0)
{
if(_loc36_ != null)
{
_loc17_.textureStrip(_loc36_,_loc2_[_loc3_.surfaceTexturePoint],_loc4_[_loc3_.surfaceTexturePoint],_loc3_.surfaceTextureMode,this.viewAngle);
}
else if(_loc20_ != 0)
{
if(_loc20_ == 1)
{
_loc11_ = this.calculateLighting(_loc22_,_loc7_,_loc6_,_loc8_).valueOf();
_loc10_ = this.calculateLighting(_loc27_,_loc7_,_loc6_,_loc8_).valueOf();
}
else
{
_loc11_ = this.calculateLighting(this.smoothNormal(_loc13_,_loc22_,_loc20_),_loc7_,_loc6_,_loc8_).valueOf();
_loc10_ = this.calculateLighting(this.smoothNormal(_loc13_,_loc27_,_loc20_),_loc7_,_loc6_,_loc8_).valueOf();
}
switch(_loc3_.smoothingQuality)
{
case 0:
default:
_loc32_ = [_loc11_,_loc10_];
break;
case 1:
_loc32_ = [_loc11_,this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf(),_loc10_];
break;
case 2:
var _loc23_ = this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf();
_loc32_ = [_loc11_,_loc23_,_loc23_,_loc10_];
}
var _loc15_ = _loc5_.length;
var _loc33_ = new GradientMatrix(_loc5_.center.x,_loc5_.center.y,_loc15_,_loc15_,this.viewSlope.x * _loc15_ * 0.5,0);
_loc17_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[1],_loc2_[2],_loc4_[2],_loc4_[1]]);
_loc34_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[0],_loc2_[1],_loc4_[1],_loc4_[0]]);
}
else
{
var _loc29_ = this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf();
_loc17_.solidShape(_loc29_,[_loc2_[1],_loc2_[2],_loc4_[2],_loc4_[1]]);
_loc34_.solidShape(_loc29_,[_loc2_[0],_loc2_[1],_loc4_[1],_loc4_[0]]);
}
}
else if(!_loc37_ && _loc3_.bottomDepth)
{
_loc29_ = this.calculateLighting(_loc13_.getReversed(),_loc7_,_loc6_,_loc8_).valueOf();
_loc38_.solidShape(_loc29_,[_loc2_[3],_loc2_[4],_loc4_[4],_loc4_[3]]);
}
if(_loc19_ && _loc3_.thickness > 0)
{
var _loc12_ = _loc3_.thickness;
(_loc16_ = new Vector((- _loc5_.normal.x) * _loc12_,(- _loc5_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
_loc14_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
if(_loc3_.sideSmoothing)
{
var _loc31_ = undefined;
var _loc30_ = undefined;
(_loc31_ = new Vector((- _loc21_.normal.x) * _loc12_,(- _loc21_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
(_loc30_ = new Vector((- _loc26_.normal.x) * _loc12_,(- _loc26_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
_loc11_ = this.calculateLighting(this.smoothNormal(_loc16_,_loc31_,_loc3_.sideSmoothing),_loc7_,_loc6_,_loc8_).valueOf();
_loc10_ = this.calculateLighting(this.smoothNormal(_loc16_,_loc30_,_loc3_.sideSmoothing),_loc7_,_loc6_,_loc8_).valueOf();
_loc33_ = new GradientMatrix((_loc2_[2].x + _loc4_[3].x) / 2,(_loc2_[2].y + _loc4_[3].y) / 2,_loc5_.length,_loc5_.length,this.viewSlope.x * _loc15_ * 0.5,0);
switch(_loc3_.smoothingQuality)
{
case 0:
default:
_loc32_ = [_loc11_,_loc10_];
break;
case 1:
_loc32_ = [_loc11_,_loc14_,_loc10_];
break;
case 2:
_loc32_ = [_loc11_,_loc14_,_loc14_,_loc10_];
}
_loc17_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
}
else
{
_loc35_.solidShape(_loc14_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
}
}
else
{
_loc35_.solidShape(_loc14_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
}
if(_loc3_.sideTexture != null)
{
this.setLayer(_loc3_.sideTextureLayer);
this.assetStrip(_loc3_.sideTexture,_loc2_[_loc3_.sideTexturePoint],_loc4_[_loc3_.sideTexturePoint],_loc3_.sideTextureMode,_loc3_.sideTextureAlign,true);
}
_loc26_ = _loc21_;
_loc27_ = _loc22_;
_loc4_ = _loc2_;
}
this.setLayer(_loc3_.bottomSurfaceLayer);
this.inst.push.apply(this.inst,_loc38_.inst);
this.setLayer(_loc3_.frontSurfaceLayer);
this.inst.push.apply(this.inst,_loc17_.inst);
this.setLayer(_loc3_.sideSurfaceLayer);
this.inst.push.apply(this.inst,_loc35_.inst);
this.setLayer(_loc3_.rearSurfaceLayer);
this.inst.push.apply(this.inst,_loc34_.inst);
}
function smoothNormal(a, b, i)
{
return new Vector(a.x * (1 - i) + b.x * i,a.y * i + b.y * i,0).normalize();
}
}